﻿CREATE FUNCTION [dbo].[fn_FormatNumLZ](@Number [int], @length [int])
RETURNS [nvarchar](10) WITH EXECUTE AS CALLER
AS 
begin
declare @FormatNum nvarchar(10)
if @length < 1 or @length > 10 or @length < len(@Number)
    set @length = len(@Number) 
set @FormatNum = right(replicate('0', @length) + cast(@Number as varchar(10)), @length)
return @FormatNum
end


